<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author YDZ
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar>
        <a-button type="primary" @click="handleForm({})" v-auth="'process:job:pmParcraetetsflow:edit'">
          <Icon icon="fluent:add-12-filled" /> {{ t('新增') }}
        </a-button>
      </template>
      <template #firstColumn="{ record }">
        <a @click="handleForm({ id: record.id })">
          {{ record.name }}
        </a>
      </template>
    </BasicTable>
    <InputForm @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsProcessJobPmParcraetetsflowList',
  });
</script>
<script lang="ts" setup>
  import { defineComponent } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { pmParcraetetsflowDelete, pmParcraetetsflowListData } from '/@/api/process/job/pmParcraetetsflow';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';
  import InputForm from './form.vue';

  const { t } = useI18n('process.job.pmParcraetetsflow');
  const { showMessage } = useMessage();
  const getTitle = {
    icon: router.currentRoute.value.meta.icon || 'ant-design:book-outlined',
    value: router.currentRoute.value.meta.title || t('接水扩展管理'),
  };

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [
      {
        label: t('name'),
        field: 'name',
        component: 'Input',
      },
      {
        label: t('创建时间'),
        field: 'createDate',
        component: 'DatePicker',
        componentProps: {
          format: 'YYYY-MM-DD HH:mm',
          showTime: { format: 'HH:mm' },
        },
      },
      {
        label: t('流程标题'),
        field: 'requestname',
        component: 'Input',
      },
      {
        label: t('流程标识'),
        field: 'flowcode',
        component: 'Input',
      },
      {
        label: t('流程创建人'),
        field: 'creatercode',
        component: 'Input',
      },
      {
        label: t('停水时段-开始'),
        field: 'cutintervaldate',
        component: 'DatePicker',
        componentProps: {
          format: 'YYYY-MM-DD HH:mm',
          showTime: { format: 'HH:mm' },
        },
      },
      {
        label: t('停水时段-结束'),
        field: 'endcutintervaldate',
        component: 'DatePicker',
        componentProps: {
          format: 'YYYY-MM-DD HH:mm',
          showTime: { format: 'HH:mm' },
        },
      },
      {
        label: t('停水时间'),
        field: 'cuthours',
        component: 'Input',
      },
      {
        label: t('影响户数'),
        field: 'influencesnum',
        component: 'Input',
      },
      {
        label: t('涉及管道直径'),
        field: 'pipediameter',
        component: 'Input',
      },
      {
        label: t('计划类别'),
        field: 'programcategory',
        component: 'Input',
      },
      {
        label: t('停水规模'),
        field: 'scale',
        component: 'Select',
        componentProps: {
          dictType: 'zf_stopWater_std',
          allowClear: true,
        },
      },
      {
        label: t('年度编号'),
        field: 'annualplanno',
        component: 'Input',
      },
      {
        label: t('enclosure'),
        field: 'enclosure',
        component: 'Input',
      },
      {
        label: t('计划停水领导小组长'),
        field: 'groupleader',
        component: 'Input',
      },
      {
        label: t('申请部门现场负责人及联系方式'),
        field: 'sceneleaderandcontact',
        component: 'Input',
      },
      {
        label: t('停水原因'),
        field: 'cutreason',
        component: 'Input',
      },
      {
        label: t('停水范围'),
        field: 'cutrange',
        component: 'Input',
      },
      {
        label: t('部门负责人'),
        field: 'depthead',
        component: 'Input',
      },
      {
        label: t('是否由科室负责人审批'),
        field: 'isdeptheadapproved',
        component: 'Input',
      },
      {
        label: t('enclosurename'),
        field: 'enclosurename',
        component: 'Input',
      },
      {
        label: t('单据状态'),
        field: 'result',
        component: 'Input',
      },
      {
        label: t('主表ID'),
        field: 'mid',
        component: 'Input',
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('name'),
      dataIndex: 'name',
      key: 'a.name',
      sorter: true,
      width: 230,
      align: 'left',
      slot: 'firstColumn',
    },
    {
      title: t('创建时间'),
      dataIndex: 'createDate',
      key: 'a.createtime',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('流程标题'),
      dataIndex: 'requestname',
      key: 'a.requestname',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('流程标识'),
      dataIndex: 'flowcode',
      key: 'a.flowcode',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('流程创建人'),
      dataIndex: 'creatercode',
      key: 'a.creatercode',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('停水时段-开始'),
      dataIndex: 'cutintervaldate',
      key: 'a.cutintervaldate',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('停水时段-结束'),
      dataIndex: 'endcutintervaldate',
      key: 'a.endcutintervaldate',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('停水时间'),
      dataIndex: 'cuthours',
      key: 'a.cuthours',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('影响户数'),
      dataIndex: 'influencesnum',
      key: 'a.influencesnum',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('涉及管道直径'),
      dataIndex: 'pipediameter',
      key: 'a.pipediameter',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('计划类别'),
      dataIndex: 'programcategory',
      key: 'a.programcategory',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('停水规模'),
      dataIndex: 'scale',
      key: 'a.scale',
      sorter: true,
      width: 130,
      align: 'center',
      dictType: 'zf_stopWater_std',
    },
    {
      title: t('年度编号'),
      dataIndex: 'annualplanno',
      key: 'a.annualplanno',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('enclosure'),
      dataIndex: 'enclosure',
      key: 'a.enclosure',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('计划停水领导小组长'),
      dataIndex: 'groupleader',
      key: 'a.groupleader',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('申请部门现场负责人及联系方式'),
      dataIndex: 'sceneleaderandcontact',
      key: 'a.sceneleaderandcontact',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('停水原因'),
      dataIndex: 'cutreason',
      key: 'a.cutreason',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('停水范围'),
      dataIndex: 'cutrange',
      key: 'a.cutrange',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('部门负责人'),
      dataIndex: 'depthead',
      key: 'a.depthead',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('是否由科室负责人审批'),
      dataIndex: 'isdeptheadapproved',
      key: 'a.isdeptheadapproved',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('enclosurename'),
      dataIndex: 'enclosurename',
      key: 'a.enclosurename',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('单据状态'),
      dataIndex: 'result',
      key: 'a.result',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('主表ID'),
      dataIndex: 'mid',
      key: 'a.mid',
      sorter: true,
      width: 130,
      align: 'left',
    },
  ];

  const actionColumn: BasicColumn = {
    width: 160,
    actions: (record: Recordable) => [
      {
        icon: 'clarity:note-edit-line',
        title: t('编辑接水扩展'),
        onClick: handleForm.bind(this, { id: record.id }),
        auth: 'process:job:pmParcraetetsflow:edit',
      },
      {
        icon: 'ant-design:delete-outlined',
        color: 'error',
        title: t('删除接水扩展'),
        popConfirm: {
          title: t('是否确认删除接水扩展'),
          confirm: handleDelete.bind(this, { id: record.id }),
        },
        auth: 'process:job:pmParcraetetsflow:edit',
      },
    ],
  };

  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerTable, { reload, getForm }] = useTable({
    api: pmParcraetetsflowListData,
    beforeFetch: (params) => {
      return params;
    },
    columns: tableColumns,
    actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  function handleForm(record: Recordable) {
    openDrawer(true, record);
  }

  async function handleDelete(record: Recordable) {
    const res = await pmParcraetetsflowDelete(record);
    showMessage(res.message);
    handleSuccess();
  }

  function handleSuccess() {
    reload();
  }
</script>
